import json
from django.db.models import Q, F
from apps.merchant.item.dao import ItemBaseSerializer, ItemDao
from apps.merchant.sku.dao import SkuBaseSerializer, SkuDao
from django.db import transaction
import logging

logger = logging.getLogger(__name__)

@transaction.atomic
def buyItemHandle(order):
    try:
        content = json.loads(order.content)
        # print('content', content)
        for item in content.get('orderItemList'):
            if item.get('sku'):
                # 销量加一
                SkuDao().addSales(item.get('sku'), item.get('payCount'))
                ItemDao().addSales(item.get('item'), item.get('payCount'))
    except Exception as e:
        logger.error(f"Error processing order: {e}")
